﻿using AutoMapper;
using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.Commands.EnterpriseCommands
{
    public class EnterpriseproviceListRequestHandler : IRequestHandler<EnterpriseproviceListsRequestModel, Result>
    {
        public IBaseRepository<County> CountyRepository;
        public IMapper mapper;

        public EnterpriseproviceListRequestHandler(IBaseRepository<County> countyRepository, IMapper mapper)
        {
            CountyRepository = countyRepository;
            this.mapper = mapper;
        }

        public Task<Result> Handle(EnterpriseproviceListsRequestModel request, CancellationToken cancellationToken)
        {
            Result result = new Result();
            result.Code = 1;
            result.Messege = "成功";
            var res = CountyRepository.GetAll().Where(x => x.CityId == request.CityId).ToList();
            List<EnterpriseproviceListsResponsetModel> lists = new List<EnterpriseproviceListsResponsetModel>();
            foreach (var item in res)
            {
                var sf = mapper.Map<EnterpriseproviceListsResponsetModel>(item);
                lists.Add(sf);
            }
            result.Data = lists;
            return Task.FromResult(result);
        }
    }
}
